import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../provider/cart.dart';
class Manage extends StatefulWidget {
  Manage({this.count});

  final int count;

  @override
  _ManageState createState() => _ManageState();
}

class _ManageState extends State<Manage> {
  int count;

  @override
  void initState() {
    setState(() {
      count = widget.count;
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    var cart=Provider.of<Cart>(context);
    return Container(
      padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 25.w),
      decoration: BoxDecoration(color: Colors.white),
      child: Row(
        children: [
          Expanded(
            child: Row(
              children: [
                Text(
                  '购物数量',
                  style: TextStyle(fontSize: 25.sp),
                ),
                SizedBox(
                  width: 10.w,
                ),
                Text(
                  '${count}',
                  style: TextStyle(color: Colors.red, fontSize: 35.sp),
                )
              ],
            ),
          ),
          count==0?Text(''):Container(
            width: 120.w,
            height: 50.w,
            child: OutlineButton(
              borderSide: BorderSide(color: Colors.black54),
              child: AnimatedSwitcher(
                transitionBuilder: (child, anim) {
                  return ScaleTransition(child: child, scale: anim);
                },
                duration: Duration(milliseconds: 100),
                child: cart.isEdit
                    ? Text('取消', key: UniqueKey())
                    : Text('管理', key: UniqueKey()),
              ),
              onPressed: () {
                cart.setEdit(!cart.isEdit);
//                setState(() {
//                  isEdit = !isEdit;
//                });
              },
            ),
          )
        ],
      ),
    );
  }
}
